import http from '@/common/request.js'

/**
 * @消息通知
 */
export const notice = {
  /**
   * @description ：根据学生uid查询用户需要接收的所有通知-有联合索引[noticeRelationId和uid组成联合索引]
   * 1. not in查询，根据学生id查询t_notice_relation表里是否有包含对应noticeId的通知，包含且已经删除则不予发送
   * 2. 如果用户注册时间大于通知时间则不予发送
   * 3. 如果t_notice_relation表里的通知记录已被删除则不予发送
   * @param token 请求头token参数
   */
  getAllNoticeInfoByUid: (token) => {
    return http.get(`notice/list`, {
      "Authorization": token
    })
  },

  /**
   * @description ：当用户点击阅读消息之后，直接根据用户接收的通知noticeId和学生uid添加对应消息记录到t_notice_relation表中，默认设置为已阅读状态[1]
   * @param token 请求头token参数
   * @param noticeId t_notice表主键id
   */
  addNoticeRelationInfo: (token, noticeId) => {
    return http.put(`notice/notice/read?noticeId=${noticeId}`, {}, {
      "Authorization": token
    })
  },

  /**
   * @description ：当用户点击删除/清空消息时，根据noticeId和uid将isDelete字段修改为1
   * @param token 请求头token参数
   * @param noticeId t_notice表主键id
   */
  editNoticeRelationInfo: (token, noticeId) => {
    return http.delete(`notice/notice/delete/${noticeId}`, {
      "Authorization": token
    })
  }
}


/**
 * @今日菜系
 */
export const todayCuisine = {
  /**
   * @description 查询今日菜系所有菜品-可根据今日24小时查询新上新菜品
   * @param is24Hour 是否根据24小时内查询上新的菜品
   */
  getAllTodayCuisineInfo: (is24Hour) => {
    return http.get(`todayCuisine/list?is24Hour=${is24Hour || false}`)
  }
}

/**
 * @场馆预约
 */
export const sports = {
  /**
   * @description 查询所有场馆信息，可根据场馆类型查询
   * @param type 场馆类型
   */
  getAllSportsInfo: (type) => {
    return http.get(`sports/list?type=${type || ""}`)
  },

  /**
   * @description 根据场馆id获取场馆详情信息-包括预约的时间段
   * @param sportsId 场馆id
   * @param orderDate 预约日期（可选）
   */
  getSportsBySportsIdInfo: (sportsId, orderDate) => {
    if (orderDate) {
      return http.get(`sports/sports?sportsId=${sportsId}&orderDate=${orderDate}`)
    } else {
      return http.get(`sports/sports?sportsId=${sportsId}`)
    }
  },

  /**
   * @description 根据学生uid添加预约记录信息
   * @param token 请求头token参数
   * @param sportsOrder 预约记录信息
   */
  addSportsOrderInfo: (token, sportsOrder) => {
    return http.post(`sports/sportsOrder`, {
      "sportsId": sportsOrder.sportsId,
      "orderDate": sportsOrder.orderDate,
      "orderStartDate": sportsOrder.startDate,
      "orderEndDate": sportsOrder.endDate
    }, {
      "Authorization": token
    })
  },

  /**
   * @description 根据学生uid查询已预约的记录信息
   * @param token 请求头token参数
   */
  getSportsOrderByUidInfo: (token) => {
    return http.get(`sports/sportsOrder/user`, {
      "Authorization": token
    })
  }
}

/**
 * @用户个人中心Api
 */
export const user = {
  /**
   * @description 登陆
   * @param studentIdOrPhoneNumber 学号或手机号码
   * @param password 密码
   */
  login: (studentIdOrPhoneNumber, password) => {
    return http.post(`user/login`, {
      "studentId": studentIdOrPhoneNumber,
      "password": password
    })
  },

  /**
   * @description 注册
   * @param user 用户基本信息
   */
  register: (user) => {
    return http.post(`user/register`, {
      "username": user.username,
      "password": user.password,
      "sex": user.sex,
      "studentId": user.studentId,
      "department": user.department,
      "phoneNumber": user.phoneNumber,
      "birthday": user.birthday,
      "question": user.question,
      "answer": user.answer
    })
  },

  /**
   * @description 查询用户基本信息
   * @param token 请求头token参数
   */
  getUserInfoByToken: (token) => {
    return http.get(`user/getInfo`, {
      "Authorization": token
    })
  },

  /**
   * @description 修改用户基本信息
   * @param token 请求头token参数
   * @param user 用户基本信息
   */
  editUserInfoByToken: (token, user) => {
    return http.post(`user/editUserInfo`, {
      "avatar": user.avatar,
      "username": user.username,
      "introduce": user.introduce,
      "sex": user.sex,
      "birthday": user.birthday,
      // "email": user.email,
      "qqNumber": user.qqNumber,
      "wxNumber": user.wxNumber,
      "department": user.department
    }, {
      "Authorization": token
    })
  },

  /**
   * @description 查询用户所有已发布的咨询
   * @param token 请求头token参数
   */
  getPressAllInfoByUid: (token) => {
    return http.get(`user/publish-press/list`, {
      "Authorization": token
    })
  },

  /**
   * @description 查询用户所有已发表的评论
   * @param token 请求头token参数
   */
  getCommentAllInfoByUid: (token) => {
    return http.get(`user/publish-comment/list`, {
      "Authorization": token
    })
  },

  /**
   * @description 根据咨询pressId和用户uid，删除对应的咨询表t_press中的数据，删除对应的评论表，删除对应的咨询点赞表
   * @param token 请求头token参数
   * @param pressId 咨询主键id
   */
  delPressInfoByPressIdAndUid: (token, pressId) => {
    return http.delete(`user/press/detail/${pressId}`, {
      "Authorization": token
    })
  },

  /**
   * @description 根据评论commentId和用户uid，删除对应的评论表
   * @param token 请求头token参数
   * @param commentId 评论主键id
   */
  delCommentInfoByCommentIdAndUid: (token, commentId) => {
    return http.delete(`user/comment/detail/${commentId}`, {
      "Authorization": token
    })
  },

  /**
   * @description 根据咨询pressId和用户uid，编辑对应的咨询表t_press中的数据
   * @param token 请求头token参数
   * @param press 咨询数据
   */
  editPressByPressIdAndUid: (token, press) => {
    return http.post(`user/press/edit`, {
      "pressId": press.pressId,
      "content": press.content,
      "pressImages": press.pressImages,
      "wxNumber": press.wxNumber,
      "qqNumber": press.qqNumber,
      "phoneNumber": press.phoneNumber,
      "publishProvince": press.publishProvince
    }, {
      "Authorization": token
    })
  },

  /**
   * @description 绑定邮箱-更换绑定邮箱
   * @param token 请求头token参数
   * @param verificationCode 邮箱验证码
   */
  editEmailInfo: (token, email, verificationCode, checkOnly) => {
    return http.get(
      `user/email/binding?email=${email}&verificationCode=${verificationCode}&checkOnly=${checkOnly || ""}`, {
        "Authorization": token
      })
  },

  /**
   * @description 根据邮箱验证码重置密码
   * @param token 请求头token参数
   * @param verificationCode 邮箱验证码
   * @param password 新密码
   */
  editPwdByEmailCode: (token, email, verificationCode, password) => {
    return http.get(
      `user/email/forgetPwd?email=${email}&verificationCode=${verificationCode}&password=${password}`, {
        "Authorization": token
      })
  },

  /**
   * @description 修改密码
   * @param token 请求头token参数
   * @param oldPassword 旧密码
   * @param newPassword 新密码
   */
  resetPwd: (token, oldPassword, newPassword) => {
    return http.post(`user/resetPwd`, {
      "oldPassword": oldPassword,
      "newPassword": newPassword
    }, {
      "Authorization": token
    })
  }
}

/**
 * 公共接口
 */
export const common = {
  /**
   * @description 发送绑定邮箱邮件验证码
   * @param token 请求头token参数
   * @param email 接收方邮箱
   */
  emailBinding: (token, email) => {
    return http.get(`common/email?email=${email}&type=emailBinding`, {
      "Authorization": token
    })
  },

  /**
   * @description 发送重置密码邮件验证码
   * @param token 请求头token参数
   * @param email 接收方邮箱
   */
  resetPasswordEmail: (token, email, password) => {
    return http.get(`common/email?email=${email}&type=forgetPwd`, {
      "Authorization": token
    })
  }
}

/**
 * @首页Api
 */
export const index = {
  /**
   * @description 获取首页轮播图，默认获取全部
   * @param type [0为首页轮播图，1未暂未定]
   */
  getSlideshowAllByType: (type) => {
    return http.get(`slideshow/list?type=${type}`)
  },

  /**
   * @description 获取咨询分类，默认获取全部
   */
  getConsultListInfo: () => {
    return http.get(`consult/list`)
  },

  /**
   * @description 获取最新咨询列表，默认根据最新发布时间排序
   * @param press 根据条件查询，里面包含[consultId,status,uid] 咨询类别id,状态,用户id
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  getPressListInfoByMore: (consultId, status, pageNum, pageSize) => {
    return http.get(
      `press/list?consultId=${consultId || ""}&status=${status || ""}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`
    )
  },

  /**
   * @description 获取24小时内热门的咨询列表
   * @param press 根据条件查询，里面包含[consultId,status,uid] 咨询类别id,状态,用户id
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  getPressListInfoByInterval24HourHot: (consultId, status, pageNum, pageSize) => {
    return http.get(
      `press/24Hour-hot/list?consultId=${consultId || ""}&status=${status || ""}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`
    )
  },

  /**
   * @description 获取历史最热门的咨询列表
   * @param press 根据条件查询，里面包含[consultId,status,uid] 咨询类别id,状态,用户id
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  getPressListInfoByMostHot: (consultId, status, pageNum, pageSize) => {
    return http.get(
      `press/most-hot/list?consultId=${consultId || ""}&status=${status || ""}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`
    )
  },

  /**
   * @description 获取最新评论时间的咨询
   * @param press 根据条件查询，里面包含[consultId,status,uid] 咨询类别id,状态,用户id
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  getPressListInfoByNewCommentDate: (consultId, status, pageNum, pageSize) => {
    return http.get(
      `press/newCommentDate/list?consultId=${consultId || ""}&status=${status || ""}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`
    )
  }
}

/**
 * @获取评论列表
 */
export const comment = {
  /**
   * @description 获取咨询详情页评论列表，默认获取全部
   * @param pressId 咨询编号id
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  getCommentInfoByPressId: (pressId, pageNum, pageSize) => {
    return http.get(
      `press/comment/list?pressId=${pressId || ""}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`)
  },

  /**
   * @description 发表评论
   * @param press 需要发表的评论信息
   */
  publishComment: (token, comment) => {
    return http.post(`press/publishComment`, {
      "pressId": comment.pressId,
      "content": comment.content,
      "contentImages": comment.contentImages,
      "commentProvince": comment.commentProvince
    }, {
      "Authorization": token
    })
  },
}


/**
 * @发布话题pi
 */
export const press = {
  /**
   * @description 发布咨询/话题
   * @param press 需要发布的信息
   */
  publishPress: (token, press) => {
    return http.post(`press/publishPress`, {
      "consultId": press.consultId,
      "content": press.content,
      "pressImages": press.pressImages,
      "wxNumber": press.wxNumber,
      "qqNumber": press.qqNumber,
      "phoneNumber": press.phoneNumber,
      "publishProvince": press.publishProvince
    }, {
      "Authorization": token
    })
  },

  /**
   * @description 根据pressId，获取咨询的详情信息
   * @param token 请求头token参数
   * @param pressId 咨询主键id
   */
  getPressInfoByPressId: (token, pressId) => {
    return http.get(`press/press?pressId=${pressId}`, {
      "Authorization": token || ""
    })
  },

  /**
   * @description 咨询点赞操作-数据库中有使用联合唯一索引，所以会有重复的点赞会自动排除
   * @param token 请求头token参数
   * @param pressId 咨询主键id
   */
  pressLike: (token, pressId) => {
    return http.put(`press/like?pressId=${pressId}`, {}, {
      "Authorization": token
    })
  },

  /**
   * @description 咨询取消点赞操作
   * @param token 请求头token参数
   * @param pressId 咨询主键id
   */
  pressCancelLike: (token, pressId) => {
    return http.put(`press/cancel-like?pressId=${pressId}`, {}, {
      "Authorization": token
    })
  },

  /**
   * @description 搜索（全文检索）
   * @param searchValue 需要搜索的内容（长度必须大于2）
   * @param pageNum 页码
   * @param pageSize 每页显示的数量
   */
  searchPressInfo: (searchValue, pageNum, pageSize) => {
    return http.get(`press/search?searchValue=${searchValue}&pageNum=${pageNum || ""}&pageSize=${pageSize || ""}`)
  }
}
